package cc.linker.steplink.crm.commons.utils;

import org.apache.commons.lang.StringUtils;

import java.util.*;

public class CommUtils {

    public static Map<String,Object> mapRemoveNull(Map<String,Object> sourceMap){
        Map<String,Object> targetMap = new HashMap<String,Object>();
        if(sourceMap!=null){
            Set<String> keySet = sourceMap.keySet();
            for (String key:keySet) {
                if(sourceMap.get(key)!=null&&StringUtils.isNotEmpty(sourceMap.get(key).toString())){
                    targetMap.put(key,sourceMap.get(key));
                }
            }
        }
        return targetMap;
    }

    public static List<String> removeDuplicate(List<String> list) {
        HashSet<String> set = new HashSet<String>(list.size());
        List<String> result = new ArrayList<String>(list.size());
        for (String str : list) {
            if (set.add(str)) {
                result.add(str);
            }
        }
        list.clear();
        list.addAll(result);
        return list;
    }

    public static List<String> getInexistenceValue(String[] strs1,String[] strs2){
        List<String> strs = new ArrayList<>();
        for (String newGroupId : strs1) {
            boolean isExit = false;
            for (String oldGroupId : strs2) {
                if (newGroupId.equals(oldGroupId)) {
                    isExit = true;
                }
            }
            if(!isExit){
                strs.add(newGroupId);
            }
        }
        return  strs;
    }

}
